package org.opens.service.impl;

import cn.hutool.core.lang.Assert;
import org.opens.dao.EduClassDao;
import org.opens.entity.EduClass;
import org.opens.service.EduClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Date 2020/12/30 21:20
 * @Created by 99126
 */
@Service
public class EduClassServiceImpl implements EduClassService {

    @Autowired
    private EduClassDao eduClassDao;

    @Override
    public EduClass insertAndReturnPK(EduClass eduClass) {
        Assert.notNull(eduClass, "保存对象不能为null");
        Assert.notEmpty(eduClass.getClassName(), "班级名称不能为空");

        eduClass.setCreateDate(new Date());
        Integer rowsAffected = eduClassDao.insertAndReturnPK(eduClass);

        return eduClass;
    }

    @Override
    public EduClass insertAndReturnPKUseSelectKey(EduClass eduClass) {
        Assert.notNull(eduClass, "保存对象不能为null");
        Assert.notEmpty(eduClass.getClassName(), "班级名称不能为空");

        eduClass.setCreateDate(new Date());
        eduClass.setCreateDate(new Date());
        Integer rowsAffected = eduClassDao.insertAndReturnPKUseSelectKey(eduClass);

        return eduClass;
    }

    @Override
    public EduClass findByIdUseIndexParam(Integer id) {
        Assert.notNull(id, "查询id不能为空");

        return eduClassDao.findByIdUseIndexParam(id);
    }

    @Override
    public EduClass findByIdUseIndexParamAlias(Integer id) {
        Assert.notNull(id, "查询id不能为空");

        return eduClassDao.findByIdUseIndexParamAlias(id);
    }

    @Override
    public EduClass findByIdUseParamName(Integer id) {
        Assert.notNull(id, "查询id不能为空");

        return eduClassDao.findByIdUseParamName(id);
    }

    @Override
    public EduClass findOneToOne(Integer id) {
        Assert.notNull(id, "查询id不能为空");

        return eduClassDao.findOneToOne(id);
    }

    @Override
    public EduClass findOneToMany(Integer id) {
        Assert.notNull(id, "查询id不能为空");

        return eduClassDao.findOneToMany(id);
    }

    @Override
    public EduClass findByIdUseProcedure(EduClass eduClass) {
        Assert.notNull(eduClass);
        Assert.notNull(eduClass.getClassId());

        return eduClassDao.findByIdUseProcedure(eduClass);
    }

    @Override
    public List<EduClass> pageUseProcedure(Map<String, Object> param) {
        Assert.notNull(param);

        return eduClassDao.pageUseProcedure(param);
    }

    @Override
    public int deleteUseProcedure(Integer classId) {
        Assert.notNull(classId);

        return eduClassDao.deleteUseProcedure(classId);
    }

    @Override
    public int insertUseProcedure(EduClass eduClass) {
        Assert.notNull(eduClass);

        return eduClassDao.insertUseProcedure(eduClass);
    }
}
